package cn.cdiothree.service.impl;


import cn.cdiothree.dao.UserMapper;
import cn.cdiothree.domain.auth.User;
import cn.cdiothree.service.UserService;
import cn.cdiothree.vo.ResultVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 用户服务
 * @author cumthing
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    UserMapper userMapper;

    /**
     * 查询在线用户人数
     * @param gap
     * @return
     */
    @Override
    public ResultVo onlineUser(Long gap) {
        Long nowTime = System.currentTimeMillis();
        Date nowDate = new Date(nowTime);
        Date validDate = new Date(nowTime-gap);
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("update_time", validDate, nowDate);
        Integer count = userMapper.selectCount(queryWrapper);
        return ResultVo.success(count);
    }
}
